﻿using System;
using System.Windows;

namespace Perspective.Wpf3D.Primitives
{
    /// <summary>
    /// 包含圆锥特征的三维模型基类
    /// Basic abstract class for Perspective.Wpf3D elements with 
    /// an inner GeometryModel3D with conical dimensions.  
    /// </summary>
    public class ConicalElement3D : PolygonalElement3D
    {
        #region Constructors

        /// <summary>
        /// Static constructor.
        /// No default back material for 3D closed shapes.
        /// </summary>
        static ConicalElement3D()
        {
            BackMaterialProperty.OverrideMetadata(
                typeof(ConicalElement3D),
                new PropertyMetadata(
                    null, 
                    VisualPropertyChanged));
        }

        #endregion

        #region Properties

        #region BottomRadius 底面半径
        /// <summary>
        /// Gets or sets the conical bottom radius.
        /// Default value is 10.0.
        /// </summary>
        public double BottomRadius
        {
            get { return (double)GetValue(BottomRadiusProperty); }
            set { SetValue(BottomRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the bottom radius dependency property.
        /// </summary>
        public static readonly DependencyProperty BottomRadiusProperty =
            DependencyProperty.Register(
                "BottomRadius",
                typeof(double),
                typeof(ConicalElement3D),
                new UIPropertyMetadata(
                    1.0,
                    VisualPropertyChanged));
        #endregion

        #region Height 高度
        /// <summary>
        /// 高度
        /// Gets or sets the model side count.
        /// Default value is 1.0. Minimum value is 0.01.
        /// </summary>
        public double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }

        /// <summary>
        /// Identifies the Height dependency property.
        /// </summary>
        public static readonly DependencyProperty HeightProperty =
            DependencyProperty.Register(
                "Height",
                typeof(double),
                typeof(ConicalElement3D),
                new PropertyMetadata(
                    1.0,
                    VisualPropertyChanged),
                    HeightValidateValue);

        /// <summary>
        /// Validation of the Height value.
        /// </summary>
        /// <param name="value">Value to test.</param>
        /// <returns>Boolean value.</returns>
        public static bool HeightValidateValue(object value)
        {
            double i = (double)value;
            return i >= 0.001;
        }
        #endregion


        #endregion
    }
}
